<!--
* @FileDescription: 联动配置
* @Author: yuec621@outlook.com
* @Date: 2025-08-15 15:28:48
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2025-10-10 09:45:09
-->
<template>
    <div class="pagestyle">
        <list_controller ref="zujianname" :options="state.options" :noprintDownShow="true">
            <template v-slot:opraCurdBtnlist="row">
                <span>
                    <el-button class="tableFontSize" type="primary" link size="small" @click="editBtn(row.row.row)">编辑
                    </el-button>
                    <el-button class="tableFontSize" type="primary" link size="small" @click="deleteBtn(row.row.row)">删除
                    </el-button>
                    <el-button class="tableFontSize" type="primary" link size="small" @click="ceshiBtn(row.row.row, 1)">
                        测试
                    </el-button>
                    <el-button class="tableFontSize" type="primary" link size="small" @click="ceshiBtn(row.row.row, 2)">
                        取消测试
                    </el-button>
                </span>
            </template>
            <template v-slot:opraCurdBtnAll>
                <el-button type="success" style="margin-right: 10px;" @click="yuyinClick">广播语音默认配置</el-button>
                <span v-if="userStore.modify" :class="state.addModal ? 'listInfoBtn active' : 'listInfoBtn'"
                    @click="addBtn()">
                    <svg-icon :class="state.addModal ? 'active' : ''" class-name="search-icon" icon-class="xinzeng" />
                    新增
                </span>
                <span v-if="userStore.modify" :class="'listInfoBtn'" @click="deleteBtn('mul')">
                    <svg-icon class-name="search-icon" icon-class="shanchu" />
                    删除
                </span>
            </template>
            <template v-slot:selectNamelist>
                联动配置
            </template>
        </list_controller>
        <!-- 新增弹框 -->
        <vxe-modal esc-closable destroy-on-close :lock-view="false" :width="1000" :height="auto"
            v-model="state.addModal" resize :mask="true" showFooter>
            <template #title>
                <div class="w100 h100 fsc mask_title">{{ state.modalTitle }}</div>
            </template>
            <template #default>
                <div class="form_box">
                    <el-form ref="formRef" :model="state.formData" :rules="state.rules" label-position="left">
                        <el-row :gutter="20">
                            <el-col :span="8">
                                <el-form-item label="联动类型选择" prop="typeName">
                                    <el-select :disabled="state.editId" class="w100" clearable filterable
                                        v-model="state.formData.typeName" placeholder="请选择" @change="typeNameChange">
                                        <el-option v-for="item in ['测点', '组合报警']" :key="item" :label="item"
                                            :value="item">
                                        </el-option>
                                    </el-select>
                                </el-form-item>
                            </el-col>
                            <el-col :span="8" v-if="state.formData.typeName == '组合报警'">
                                <el-form-item label="组合报警名称" prop="combinationIdList">
                                    <el-select :disabled="state.editId" class="w100" multiple clearable filterable
                                        v-model="state.formData.combinationIdList" placeholder="请选择">
                                        <el-option v-for="item in state.combinationIdList" :key="item.id"
                                            :label="item.combinatedAlarmName" :value="item.id">
                                        </el-option>
                                    </el-select>
                                </el-form-item>
                            </el-col>
                            <el-col :span="8" v-if="state.formData.typeName == '测点'">
                                <el-form-item label="物理量" prop="sensorType">
                                    <el-cascader :disabled="state.editId" @change="sensorTypeChange" class="w100"
                                        v-model="state.formData.sensorType" :options="state.sensorTypeList" clearable
                                        :props="{
                                            children: 'children', value: 'code', label: 'name'
                                            , checkStrictly: true, emitPath: false
                                        }" />
                                </el-form-item>
                            </el-col>
                            <el-col :span="8" v-if="state.formData.typeName == '测点'">
                                <el-form-item label="测点编号" prop="sensorName">
                                    <el-cascader v-if="state.modalTitle != '编辑联动配置'" ref="sensorNameRef"
                                        @change="sensorNameChange" class="w100" v-model="state.formData.sensorName"
                                        popper-class="popper-linkConfig" :options="state.sensorNamelList" clearable
                                        :props="{
                                            children: 'children', value: 'commonField', label: 'commonField'
                                            , multiple: true, checkStrictly: true, emitPath: false
                                        }" />
                                    <el-input :disabled="state.editId" v-else v-model="state.formData.sensorName">
                                    </el-input>
                                </el-form-item>
                            </el-col>
                            <el-col :span="24" style="background-color: rgba(91, 109, 128, 0.08);border-radius: 8px;">
                                <el-row :gutter="24">
                                    <el-col :span="24">
                                        <el-form-item label="人员定位">
                                            <el-checkbox @change="linkageStatusPer"
                                                v-model="state.formData.linkagePersonDto.linkageStatus">
                                            </el-checkbox>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="12">
                                        <el-form-item label="联动人员分站编号"
                                            :prop="state.formData.linkagePersonDto.linkageStatus ? 'linkagePersonDto.stationCode' : ''">
                                            <el-select class="w100" multiple clearable filterable collapse-tags
                                                v-model="state.formData.linkagePersonDto.stationCode" placeholder="请选择"
                                                @change="personStationCodeChange">
                                                <template #header>
                                                    <el-checkbox v-model="state.personStationCodecheckAll"
                                                        @change="personStationCodeCheckAll">
                                                        全部
                                                    </el-checkbox>
                                                </template>
                                                <el-option v-for="item in state.stationCodeList" :key="item"
                                                    :label="item" :value="item">
                                                </el-option>
                                            </el-select>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="12">
                                        <el-form-item label="联动人员标识卡号"
                                            :prop="state.formData.linkagePersonDto.linkageStatus ? 'linkagePersonDto.labelNum' : ''">
                                            <el-select :teleported="false" class="w100" multiple clearable filterable
                                                collapse-tags v-model="state.formData.linkagePersonDto.labelNum"
                                                @visible-change="handleVisibleChange" @change="personlabelNumChange"
                                                v-selectLoadmore="handleScroll" placeholder="请选择">
                                                <template #header>
                                                    <el-checkbox v-model="state.personlabelNumcheckAll"
                                                        @change="personlabelNumCheckAll">
                                                        全部
                                                    </el-checkbox>
                                                </template>
                                                <el-option v-for="item in state.labelNumList" :key="item" :label="item"
                                                    :value="item">
                                                </el-option>
                                            </el-select>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="24">
                                        <el-form-item label=""
                                            :prop="state.formData.linkagePersonDto.linkageStatus ? 'alarmStatus_four' : ''"
                                            :rules="state.rules.alarmStatus_four">
                                            <el-checkbox v-model="state.formData.linkagePersonDto.alarmStatus">报警
                                            </el-checkbox>
                                            <el-checkbox :disabled="state.formData.typeName == '组合报警'"
                                                v-model="state.formData.linkagePersonDto.cutLineStatus">断线
                                            </el-checkbox>
                                            <el-checkbox :disabled="state.formData.typeName == '组合报警'"
                                                v-model="state.formData.linkagePersonDto.calibrationStatus">标校
                                            </el-checkbox>
                                            <el-checkbox :disabled="state.formData.typeName == '组合报警'"
                                                v-model="state.formData.linkagePersonDto.prealarmStatus">预报警
                                            </el-checkbox>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                            </el-col>
                            <el-col :span="24"
                                style="background-color: rgba(91, 109, 128, 0.08);margin-top: 10px;border-radius: 8px;">
                                <el-row :gutter="24">
                                    <el-col :span="24">
                                        <el-form-item label="广播、程控">
                                            <el-checkbox v-model="state.formData.broadcastLinkageDto.broadcastStatus">
                                            </el-checkbox>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="12">
                                        <el-form-item label="广播话站编号"
                                            :prop="state.formData.broadcastLinkageDto.broadcastStatus ? 'broadcastLinkageDto.stationCode' : ''">
                                            <el-select class="w100" multiple clearable filterable collapse-tags
                                                v-model="state.formData.broadcastLinkageDto.stationCode"
                                                placeholder="请选择" @change="broadcastStationCodeChange">
                                                <template #header>
                                                    <el-checkbox v-model="state.broadcastStationCodecheckAll"
                                                        @change="broadcastStationCodeCheckAll">
                                                        全部
                                                    </el-checkbox>
                                                </template>
                                                <el-option v-for="item in state.gbstationCodeList" :key="item"
                                                    :label="item" :value="item">
                                                </el-option>
                                            </el-select>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="12">
                                        <el-form-item label="程控电话">
                                            <el-input class="w100" v-model="state.formData.broadcastLinkageDto.spcPhone"
                                                placeholder="请输入">
                                            </el-input>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="24">
                                        <el-form-item label="联动内容">
                                            <el-checkbox v-if="state.formData.typeName == '测点'"
                                                v-model="state.formData.broadcastLinkageDto.pointLocationStatus">
                                                测点位置
                                            </el-checkbox>
                                            <el-checkbox v-if="state.formData.typeName == '测点'"
                                                v-model="state.formData.broadcastLinkageDto.pointNameStatus">
                                                测点名称
                                            </el-checkbox>
                                            <el-checkbox v-if="state.formData.typeName == '组合报警'"
                                                v-model="state.formData.broadcastLinkageDto.combinationNameStatus">
                                                组合报警名称
                                            </el-checkbox>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="24">
                                        <el-form-item
                                            :prop="state.formData.broadcastLinkageDto.broadcastStatus ? 'alarmStatusgb_four' : ''"
                                            :rules="state.rules.alarmStatusgb_four"
                                            style="display: flex;justify-content: space-between;flex-wrap: wrap;width: 100%;">
                                            <div
                                                style="display: flex;align-items: center;width: 50%;margin-bottom: 10px;">
                                                <el-checkbox v-model="state.formData.broadcastLinkageDto.alarmStatus">
                                                    报警
                                                </el-checkbox>
                                                <el-input style="width: 90%;margin-left: 10px;"
                                                    v-model="state.formData.broadcastLinkageDto.alarmInfo"
                                                    placeholder="请输入">
                                                </el-input>
                                            </div>
                                            <div
                                                style="display: flex;align-items: center;width: 48%;margin-bottom: 10px;margin-left: 10px;">
                                                <el-checkbox :disabled="state.formData.typeName == '组合报警'"
                                                    v-model="state.formData.broadcastLinkageDto.cutLineStatus">
                                                    断线
                                                </el-checkbox>
                                                <el-input :disabled="state.formData.typeName == '组合报警'"
                                                    style="width: 90%;margin-left: 10px;"
                                                    v-model="state.formData.broadcastLinkageDto.cutLineInfo"
                                                    placeholder="请输入"></el-input>
                                            </div>
                                            <div style="display: flex;align-items: center;width: 50%;">
                                                <el-checkbox :disabled="state.formData.typeName == '组合报警'"
                                                    v-model="state.formData.broadcastLinkageDto.calibrationStatus">
                                                    标校
                                                </el-checkbox>
                                                <el-input :disabled="state.formData.typeName == '组合报警'"
                                                    style="width: 100%;margin-left: 10px;"
                                                    v-model="state.formData.broadcastLinkageDto.calibrationInfo"
                                                    placeholder="请输入"></el-input>
                                            </div>
                                            <div
                                                style="display: flex;align-items: center;width: 48%;margin-left: 10px;">
                                                <el-checkbox :disabled="state.formData.typeName == '组合报警'"
                                                    v-model="state.formData.broadcastLinkageDto.prealarmStatus">
                                                    预报警
                                                </el-checkbox>
                                                <el-input :disabled="state.formData.typeName == '组合报警'"
                                                    style="width: 90%;margin-left: 10px;"
                                                    v-model="state.formData.broadcastLinkageDto.prealarmInfo"
                                                    placeholder="请输入"></el-input>
                                            </div>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                            </el-col>
                        </el-row>
                    </el-form>
                </div>
            </template>
            <template #footer>
                <el-button @click="cancel">取消</el-button>
                <el-button type="primary" v-if="state.combinationIdList.length > 0
                    || state.formData.typeName == '测点' || state.editId" @click="submitForm">
                    确定
                </el-button>
            </template>
        </vxe-modal>
        <vxe-modal esc-closable destroy-on-close :lock-view="false" :width="400" :height="auto"
            v-model="state.yuyinaddModal" resize :mask="true" showFooter>
            <template #title>
                <div class="w100 h100 fsc mask_title">广播语音默认配置</div>
            </template>
            <template #default>
                <div class="form_box">
                    <el-form ref="yuyinformRef" :model="state.formDatayuyin" :rules="state.rulesyuyin"
                        label-position="left" label-width="80">
                        <el-row :gutter="20">
                            <el-col :span="24">
                                <el-form-item label="报警">
                                    <el-input v-model="state.formDatayuyin.alarmInfo" placeholder="请输入"></el-input>
                                </el-form-item>
                            </el-col>
                            <el-col :span="24">
                                <el-form-item label="断线" prop="breakageInfo">
                                    <el-input v-model="state.formDatayuyin.breakageInfo" placeholder="请输入"></el-input>
                                </el-form-item>
                            </el-col>
                            <el-col :span="24">
                                <el-form-item label="标校" prop="calibrationInfo">
                                    <el-input v-model="state.formDatayuyin.calibrationInfo" placeholder="请输入">
                                    </el-input>
                                </el-form-item>
                            </el-col>
                            <el-col :span="24">
                                <el-form-item label="预报警" prop="prealarmInfo">
                                    <el-input v-model="state.formDatayuyin.prealarmInfo" placeholder="请输入"></el-input>
                                </el-form-item>
                            </el-col>
                            <el-col :span="24">
                                <el-form-item label="组合报警" prop="calibrationAlarmInfo">
                                    <el-input v-model="state.formDatayuyin.calibrationAlarmInfo" placeholder="请输入">
                                    </el-input>
                                </el-form-item>
                            </el-col>
                        </el-row>
                    </el-form>
                </div>
            </template>
            <template #footer>
                <el-button @click="yuyinCancel">取消</el-button>
                <el-button type="primary" @click="yuyinsubmitForm">
                    确定
                </el-button>
            </template>
        </vxe-modal>
    </div>
</template>
<script setup>
import list_controller from "@/components/commonCom/list_controller";
import {
    computed,
    nextTick,
    reactive
} from "vue";
import {
    ElMessage,
    ElMessageBox
} from 'element-plus'
import {
    table_headers
} from '@/components/commonCom/table_headers';
import axios from "@/utils/request"
import usePagesStore from '@/store/modules/pages'
import useUserStore from "@/store/modules/user";
const userStore = useUserStore();
const {
    proxy
} = getCurrentInstance();
const store = usePagesStore()
const router = useRouter();
const upload = ref(null)
const validatecard = (rule, value, callback) => {
    if (!state.formData.linkagePersonDto.alarmStatus && !state.formData.linkagePersonDto.cutLineStatus && !state
        .formData.linkagePersonDto.calibrationStatus && !state.formData.linkagePersonDto.prealarmStatus)
        return callback(new Error("请选择报警、断线、标校、预报警至少一条以上!"));
    callback();
}
const validatecard1 = (rule, value, callback) => {
    if (!state.formData.broadcastLinkageDto.alarmStatus && !state.formData.broadcastLinkageDto.cutLineStatus &&
        !state
            .formData.broadcastLinkageDto.calibrationStatus && !state.formData.broadcastLinkageDto.prealarmStatus)
        return callback(new Error("请选择报警、断线、标校、预报警至少一条以上!"));
    callback();
}

let state = reactive({
    broadcastStationCodecheckAll: false,
    personStationCodecheckAll: false,
    personlabelNumcheckAll: false,
    yuyinaddModal: false,
    combinationIdList: [],
    sensorTypeList: [],
    stationCodeList: [],
    labelNumList: [],
    gbstationCodeList: [],
    sensorNameobj: {},
    options: {
        tableheads: computed(() => table_headers.linkageControl),
        queryList: {
            dropdownUrl: '',
            querys: []
        },
        dataUrl: '/linkageControl/list',
        delUrl: '/linkageControl/batchDelete',
        addUrl: '/linkageControl/addRecord',
        descUrl: '/linkageControl/detail',
        editUrl: '/linkageControl/modifyRecord',
    },
    // 表单
    addModal: false,
    modalTitle: '',
    formRef: null,
    formData: {
        pointList: [],
        sensorType: 'A',
        linkagePersonDto: {
            linkageStatus: true,
            alarmStatus: false,
            cutLineStatus: false,
            calibrationStatus: false,
            prealarmStatus: false
        },
        broadcastLinkageDto: {
            broadcastStatus: true,
            pointLocationStatus: false,
            pointNameStatus: false,
            combinationNameStatus: false,
            alarmStatus: false,
            cutLineStatus: false,
            calibrationStatus: false,
            prealarmStatus: false,
            alarmInfo: "超限报警，请附近瓦检员检察",
            cutLineInfo: "断线，请附近瓦检员检察",
            calibrationInfo: "标校，请附近瓦检员检察",
            prealarmInfo: "预报警，请附近瓦检员检察",
        }
    },
    rules: {
        typeName: [{
            required: true,
            message: '请选择联动类型选择',
            trigger: 'change'
        }],
        combinationIdList: [{
            required: true,
            message: '请选择组合报警名称',
            trigger: 'change'
        }],
        sensorName: [{
            required: true,
            message: "请选择",
            trigger: "change",
        }],
        sensorType: [{
            required: true,
            message: "请选择物理量",
            trigger: "change",
        }],
        sensorName: [{
            required: true,
            message: "请选择测点编号",
            trigger: "change",
        }],
        'linkagePersonDto.stationCode': [{
            required: true,
            message: "请选择联动人员分站编号",
            trigger: "change",
        }],
        'linkagePersonDto.labelNum': [{
            required: true,
            message: "请选择联动人员标识卡号",
            trigger: "change",
        }],
        'broadcastLinkageDto.stationCode': [{
            required: true,
            message: "请选择广播话站编号",
            trigger: "change",
        }],
        alarmStatus_four: [{
            validator: validatecard,
            trigger: 'change',
            required: true,
        }],
        alarmStatusgb_four: [{
            validator: validatecard1,
            trigger: 'change',
            required: true,
        }]
    },
    editId: undefined,
    stationmodelList: [],
    sensorNamelList: [],
    pageData: { //懒加载相关参数，这里代表从第一条数据开始加载，一次加载二十项
        pageNum: 1,
        pageSize: 20,
        loading: false,
        total: 0,
    },
    scrollTop: 0,
    formDatayuyin: {
        alarmInfo: '报警，请附近瓦检员检察',
        breakageInfo: '断线，请附近瓦检员检察',
        calibrationInfo: '标校，请附近瓦检员检察',
        prealarmInfo: '预报警，请附近瓦检员检察',
        calibrationAlarmInfo: '组合报警，请附近瓦检员检察',
    },
    rulesyuyin: {
        alarmInfo: [{
            required: true,
            message: '请选择联动类型选择',
            trigger: 'blur'
        }],
    }
})
// 多选下拉全选效果-联动人员分站编号
function personStationCodeCheckAll(val) {
    if (val) {
        state.formData.linkagePersonDto.stationCode = state.stationCodeList
    } else {
        state.formData.linkagePersonDto.stationCode = []
    }
}
function personStationCodeChange(val) {
    if (state.formData.linkagePersonDto.stationCode.length == 0) {
        state.personStationCodecheckAll = false
    } else if (state.formData.linkagePersonDto.stationCode.length == state.stationCodeList.length) {
        state.personStationCodecheckAll = true
    }
}
// 多选下拉全选效果-联动人员标识卡号
function personlabelNumCheckAll(val) {
    if (val) {
        state.formData.linkagePersonDto.labelNum = state.labelNumList
    } else {
        state.formData.linkagePersonDto.labelNum = []
    }
}
function personlabelNumChange(val) {
    if (state.formData.linkagePersonDto.labelNum.length == 0) {
        state.personlabelNumcheckAll = false
    } else if (state.formData.linkagePersonDto.labelNum.length == state.labelNumList.length) {
        state.personlabelNumcheckAll = true
    }
}

// 多选下拉全选效果-广播话站编号
function broadcastStationCodeCheckAll(val) {
    if (val) {
        state.formData.broadcastLinkageDto.stationCode = state.gbstationCodeList
    } else {
        state.formData.broadcastLinkageDto.stationCode = []
    }
}
function broadcastStationCodeChange(val) {
    if (state.formData.broadcastLinkageDto.stationCode.length == 0) {
        state.broadcastStationCodecheckAll = false
    } else if (state.formData.broadcastLinkageDto.stationCode.length == state.gbstationCodeList.length) {
        state.broadcastStationCodecheckAll = true
    }
}


// 新增按钮
function addBtn() {
    state.modalTitle = '新增联动配置'
    state.addModal = true
    state.editId = undefined
    state.formData = {
        typeName: '测点',
        pointList: [],
        sensorType: 'A',
        linkagePersonDto: {
            linkageStatus: true,
            alarmStatus: false,
            cutLineStatus: false,
            calibrationStatus: false,
            prealarmStatus: false
        },
        broadcastLinkageDto: {
            broadcastStatus: true,
            pointLocationStatus: false,
            pointNameStatus: false,
            combinationNameStatus: false,
            alarmStatus: false,
            cutLineStatus: false,
            calibrationStatus: false,
            prealarmStatus: false,
            alarmInfo: "超限报警，请附近瓦检员检察",
            cutLineInfo: "断线，请附近瓦检员检察",
            calibrationInfo: "标校，请附近瓦检员检察",
            prealarmInfo: "预报警，请附近瓦检员检察",
        }
    }
    nextTick(() => {
        proxy.$refs['formRef'].clearValidate(['linkagePersonDto.stationCode']);
    })
    getsubstationmodelList()
}
function getdetailData(id) {
    return new Promise(resolve => {
        axios.post(state.options.descUrl, {
            id: id
        }).then(res => {
            if (res.code == 200) {
                state.formData = res.data

                state.editId = res.data.id
                resolve(res.data)
            }
        })
    })
}
// 编辑按钮
function editBtn(row) {
    state.modalTitle = '编辑联动配置'
    state.addModal = true
    let data = getdetailData(row.id)
    state.formData.sensorName = [data.name]
    if (res.data.linkagePersonDto.stationCode != '') {
        state.formData.linkagePersonDto.stationCode = data.linkagePersonDto.stationCode.split(
            ',')
    } else {
        state.formData.linkagePersonDto.stationCode = []
    }
    if (res.data.linkagePersonDto.labelNum != '') {
        state.formData.linkagePersonDto.labelNum = data.linkagePersonDto.labelNum.split(',')
    } else {
        state.formData.linkagePersonDto.labelNum = []
    }
    if (res.data.broadcastLinkageDto.stationCode != '') {
        state.formData.broadcastLinkageDto.stationCode =
            data.broadcastLinkageDto.stationCode
                .split(
                    ',')
    } else {
        state.formData.broadcastLinkageDto.stationCode = []
    }
    state.formData.combinationIdList = [data.combinationId]
    getsubstationmodelList()
}


function deleteBtn(row) {
    let ids = []
    if (row != 'mul') {
        ids = [row.id]
    } else {
        if (store.records.length > 0) {
            ids = store.records.map(item => {
                return item.id
            })
        } else {
            proxy.$modal.msgSuccess('请先勾选所要删除数据!');
        }
    }
    if (ids.length > 0) {
        ElMessageBox.confirm(
            '确定要删除该数据吗?',
            '温馨提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning',
        }
        )
            .then(() => {
                axios.post(state.options.delUrl, ids).then(res => {
                    if (res.code == 200) {
                        proxy.$refs['zujianname'].getData()
                        state.addModal = false
                        ElMessage({
                            type: 'success',
                            message: res.msg,
                        })
                        store.records = []
                    }
                })

            })
            .catch(() => {
                ElMessage({
                    type: 'info',
                    message: '删除取消',
                })
            })
    }
}

function linkageStatusPer(val) {
    if (!val) {
        console.log(val, "清楚")
    }

}
/** 提交按钮 */
function submitForm() {
    proxy.$refs["formRef"].validate(valid => {
        if (valid) {
            state.formData.sensorName = state.formData.sensorName && state.formData.sensorName.join(',')
            state.formData.linkagePersonDto.labelNum = state.formData.linkagePersonDto.labelNum && state
                .formData.linkagePersonDto.labelNum
                .join(',')

            state.formData.linkagePersonDto.stationCode = state.formData.linkagePersonDto.stationCode &&
                state.formData.linkagePersonDto
                    .stationCode.join(
                        ',')
            state.formData.broadcastLinkageDto.stationCode = state.formData.broadcastLinkageDto
                .stationCode && state.formData
                    .broadcastLinkageDto.stationCode
                    .join(',')
            if (state.editId) {
                state.formData.id = state.editId
                axios.post(state.options.editUrl, state.formData).then(res => {
                    if (res.code == 200) {
                        proxy.$refs['zujianname'].getData()
                        state.addModal = false
                        proxy.$modal.msgSuccess(res.msg);
                    }
                })
            } else {
                axios.post(state.options.addUrl, state.formData).then(res => {
                    if (res.code == 200) {
                        proxy.$refs['zujianname'].getData()
                        state.addModal = false
                        proxy.$modal.msgSuccess(res.msg);
                    }
                })
            }
        }
    })
}

function cancel() {
    state.addModal = false
}

function typeNameChange(val) {
    if (val == '组合报警') {
        state.formData.linkagePersonDto.alarmStatus = true
        state.formData.broadcastLinkageDto.alarmStatus = true
    } else if (val == '测点') {
        state.formData.linkagePersonDto.alarmStatus = false
        state.formData.broadcastLinkageDto.alarmStatus = false
    }
}

function sensorTypeChange(val) {
    state.sensorNameobj = {
        condition: val
    }
    getconditionList()
}

function sensorNameChange(val) {
    if (proxy.$refs['sensorNameRef'].getCheckedNodes() && proxy.$refs['sensorNameRef'].getCheckedNodes().length >
        0) {
        proxy.$refs['sensorNameRef'].getCheckedNodes().forEach(item => {
            state.formData.pointList.push(item.data)
        })

    }
}

function getconditionList() {
    // 测点
    axios.get('/linkageControl/attainExclusionList').then(res => {
        state.sensorNameobj.exclusionPointList = res.data
        axios.post('/hisPointFeed/conditionList', state.sensorNameobj).then(res => {
            state.sensorNamelList = res.data
        })
    })
}

// 模拟获取数据
const fetchData = async (reset = false) => {
    if (reset) {
        state.pageData.pageNum = 1
        state.labelNumList = []
    }
    state.pageData.loading = true
    try {
        // 这里替换为实际API调用
        const response = await mockApi()
        state.labelNumList = [...state.labelNumList, ...response.list]
        state.pageData.total = response.total
        state.pageData.pageNum++
    } finally {
        state.pageData.loading = false
    }
}

// 处理滚动事件
const handleScroll = (e) => {
    // const {
    //     scrollTop,
    //     scrollHeight,
    //     clientHeight
    // } = e.target
    // const scrollBottom = scrollHeight - (scrollTop + clientHeight)
    // 当滚动到底部且还有更多数据时加载下一页
    if (state.labelNumList.length < state.pageData.total) {
        fetchData()
    }
}

// 下拉框显示/隐藏时处理
const handleVisibleChange = (visible) => {
    if (visible && state.labelNumList.length === 0) {
        fetchData()
    }
}

// 模拟API
const mockApi = (query, page, pageSize) => {
    return new Promise(resolve => {
        axios.post('/linkageControl/attainEmpInfo', state.pageData).then(res => {
            resolve(res.data)
        })
    })
}

function yuyinClick() {
    state.yuyinaddModal = true
    axios.post('/broadcastVoice/detail', {
        id: 1
    }).then(res => {
        state.formDatayuyin = res.data
    })
}

function yuyinCancel() {
    state.yuyinaddModal = false
}

function yuyinsubmitForm() {
    if (!state.formDatayuyin.id) {
        axios.post('/broadcastVoice/addRecord', state.formDatayuyin).then(res => {
            proxy.$modal.msgSuccess(res.msg)
            state.yuyinaddModal = false
            proxy.$refs['zujianname'].getData()
        })
    } else {
        axios.post('/broadcastVoice/modifyRecord', state.formDatayuyin).then(res => {
            proxy.$modal.msgSuccess(res.msg)
            state.yuyinaddModal = false
            proxy.$refs['zujianname'].getData()
        })

    }
}
// 测试取消测试按钮
async function ceshiBtn(row, type) {
    let data = await getdetailData(row.id)
    if (type == 1) {
        await axios.post("/linkageControl/launchTest", data).then((res) => {
            proxy.$modal.msgSuccess(res.msg)
            proxy.$refs['zujianname'].getData()
        });
    } else {
        await axios.post("/linkageControl/cancelTest", data).then((res) => {
            proxy.$modal.msgSuccess(res.data)
            proxy.$refs['zujianname'].getData()
        });
    }
}

function getsubstationmodelList() {
    axios.get("/linkageControl/listCombinationInfo").then((res) => {
        state.combinationIdList = res.data
    });
    // 类型
    axios.post("/hisPointFeed/listAllNames", {}).then((res) => {
        state.sensorTypeList = res.data
    });
    axios.get('/linkageControl/stationHeadInfo').then(res => {
        state.stationCodeList = res.data
    })

    axios.get('/linkageControl/gainBroadcastInfo').then(res => {
        state.gbstationCodeList = res.data
    })
}
getconditionList()
getsubstationmodelList()
</script>
<style lang="scss">
.popper-linkConfig {
    li[aria-haspopup="true"] {
        .el-checkbox {
            display: none;
        }
    }
}
</style>